package com.ptswitch.material.pages.zip;

import org.apache.tapestry5.EventConstants;
import org.apache.tapestry5.annotations.OnEvent;
import org.apache.tapestry5.ioc.annotations.Inject;

import com.ptswitch.material.model.base.Upload;
import com.ptswitch.material.pages.base.MaterialBasePage;
import com.ptswitch.material.service.BomService;
import com.ptswitch.material.service.MaterialExcelService;
import com.ptswitch.material.service.MaterialService;

public class ExportZip extends MaterialBasePage {
    @Inject
    private MaterialExcelService excelSer;
    @Inject
    private MaterialService materialSer;
    @Inject
    private BomService bomSer;

    @OnEvent(value = EventConstants.ACTIVATE)
    Object exportZip() {
        checkUserIsAdmin();
        Upload upload = new Upload();
        upload.setFilePath("output/export.zip");
        upload.setFileName("export.zip");
        upload.setFileType("application/zip");
        excelSer.outputDataToZip(materialSer.findAll(), bomSer.findAll(), getWebUtil().getSavePath(), "output/export.zip");
        return getWebUtil().download(upload);
    }
}
